// api.js
// 封装网络请求方法
function request(url, method = 'GET', data = {}) {
	const domain='https://api.icode2023.top'
	return new Promise((resolve, reject) => {
		uni.request({
			url: domain+url,
			method: method,
			data: data,
			success: (res) => {
				const statusCode = res.statusCode
				const response = res.data
				// 判断请求状态码
				if (statusCode === 200) {
					resolve(response)
				} else {
					reject(response)
				}
			},
			fail: (err) => {
				reject(err)
			}
		})
	})
}

// 封装GET请求方法
function get(url, data = {}) {
	return request(url, 'GET', data)
}

// 封装POST请求方法
function post(url, data = {}) {
	return request(url, 'POST', data)
}

export default {
	get,
	post
}